package com.zuoban.storage.config;

import com.zuoban.storage.properties.StorageProperties;
import com.zuoban.storage.service.StorageService;
import com.zuoban.storage.service.impl.*;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @BelongsProject: zuoban-boot
 * @BelongsPackage: com.zuoban.storage.config
 * @Author: zxy
 * @CreateTime: 2022-10-10  10:59
 * @Description: 存储配置
 */
@Configuration
@EnableConfigurationProperties(StorageProperties.class) // 让配置文件生效 注入bean
@ConditionalOnProperty(prefix = "storage", value = "enable")
public class StorageConfig {

    @Bean
    public StorageService storageService(StorageProperties properties) {
        if (properties.getConfig().getType() == StorageProperties.StorageType.LOCAL) {
            return new LocalStorageServiceImpl(properties);
        } else if (properties.getConfig().getType() == StorageProperties.StorageType.ALIYUN) {
            return new AliyunStorageServiceImpl(properties);
        } else if (properties.getConfig().getType() == StorageProperties.StorageType.TENCENT) {
            return new TencentStorageServiceImpl(properties);
        } else if (properties.getConfig().getType() == StorageProperties.StorageType.QINIU) {
            return new QiniuStorageServiceImpl(properties);
        } else if (properties.getConfig().getType() == StorageProperties.StorageType.HUAWEI) {
            return new HuaweiStorageServiceImpl(properties);
        } else if (properties.getConfig().getType() == StorageProperties.StorageType.MINIO) {
            return new MinioStorageServiceImpl(properties);
        } else {
            throw new RuntimeException("没有匹配到对应的存储系统，请联系管理员");
        }
    }
}
